db = require '../base/db'

Schema = db.Schema
mongoose = db.mongoose
updated_at = db.mongoose_plugins.updated_at

# 字典模型
DictSchema = new Schema
  # 字典ID
  dict_id: String
  # 字典名称
  dict_name: String
  # 字典项
  dict_items: Schema.Types.Mixed
  # 扩展字段
  extra: Schema.Types.Mixed

# 是否自动索引
DictSchema.set('autoIndex', false)
# 设置字典ID为索引
DictSchema.index {dict_id: 1}, {unique: false}
# 设置字典名称为索引
DictSchema.index {dict_name: 1}, {unique: false}
# 设置更新时间
DictSchema.plugin updated_at, {index: true}

# 向外导出模型
module.exports = mongoose.model 's_dicts', DictSchema